#ifndef __UTILS__H__
#define __UTILS__H__
#include <Arduino.h> 
#include "EMQX.h"
#include <string.h>
struct tm time0;
int usedTime;
float userBalance;
float pricePerSecond;
String userCardId;
DynamicJsonDocument doc(1024);
bool isUsing = false;
bool isEMQXUsing = false;
bool isRC522Using = false;
String messageFromEMQX;

#define LED 2
void stopUsing(String userCardId, int usedTime) {
    String api = API + "cost/useWater?userCardId=" + userCardId + "&seconds=" + String(usedTime);
    HTTPClient http;
    Serial.println(api);
    http.begin(api); //HTTP begin
    int httpCode = http.GET();
    if (httpCode > 0) {
        String str = "使用结束，您使用了" + usedTime;
        Serial.println(str);
    }
    else {
        Serial.printf("HTTP Get Error: %s\n", http.errorToString(httpCode).c_str());
    }
    http.end();
}


String arrayToString(byte* buffer, byte bufferSize) {
    String str = "";
    for (byte i = 0; i < bufferSize; i++) {
        str = str + String(buffer[i]);
    }
    return str;
}

#endif